package com.example.fragment.tool;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.fragment.R;


public class GremSetDialog extends Dialog implements View.OnClickListener{
    private TextView mTvGrem;
    private TextView mTvTime;
    private TextView mTvTemperature;
    private TextView mTvTitle;
    private EditText mEtGrem,mEtTime,mEtTemperature;
    private Button mBtnPositive,mBtnNegtive;
    private onPositiveListener positiveListener;
    private onNegetiveListener negetiveListener;
    private String title,grem,time,temperature,gremtitle,timetitle,temperaturetitle;
    public GremSetDialog setmTvTitle(String title) {
        this.title = title;
        return this;
    }
    public GremSetDialog(@NonNull Context context) {
        super(context);
    }

    public GremSetDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected GremSetDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public GremSetDialog setmTvGrem(String gremtitle) {
        this.gremtitle = gremtitle;
        return this;
    }

    public GremSetDialog setmTvTime(String timetitle) {
        this.timetitle = timetitle;
        return this;
    }

    public GremSetDialog setmTvTemperature(String temperaturetitle) {
        this.temperaturetitle = temperaturetitle;
        return this;
    }
    public String getmEtGrem() {
        return mEtGrem.getText().toString();
    }

    public GremSetDialog setmEtGrem(String grem) {

        this.grem=grem;
        return this;
    }

    public String getmEtTime() {
        return mEtTime.getText().toString();
    }

    public GremSetDialog setmEtTime(String time) {
        this.time=time;
        return this;
    }

    public String getmEtTemperature() {
        return mEtTemperature.getText().toString();
    }

    public GremSetDialog setmEtTemperature(String temperature) {
        this.temperature=temperature;
        return this;
    }

    public Button getmBtnPositive() {
        return mBtnPositive;
    }

    public GremSetDialog setmBtnPositive(onPositiveListener positiveListener) {
       this.positiveListener=positiveListener;
        return this;
    }

    public Button getmBtnNegtive() {
        return mBtnNegtive;
    }

    public GremSetDialog setmBtnNegtive(onNegetiveListener negetiveListener) {
       this.negetiveListener=negetiveListener;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_diaolog_gremset);
        mBtnPositive=findViewById(R.id.positi_bn);
        mBtnNegtive =findViewById(R.id.navige_bn);
        mEtGrem =findViewById(R.id.et_grem);
        mEtTime =findViewById(R.id.et_settime);
        mTvTitle=findViewById(R.id.dialog_title);
        mEtTemperature =findViewById(R.id.eta_temperature);
        mTvGrem =findViewById(R.id.tv_gremtitle);
        mTvTime=findViewById(R.id.tv_timetitle);
        mTvTemperature=findViewById(R.id.tv_temperaturetitle);
       mBtnPositive.setOnClickListener(this);
       mBtnNegtive.setOnClickListener(this);

        //设定标题，文字
        if(!TextUtils.isEmpty(title)){
            mTvTitle.setText(title);
        }
        if(!TextUtils.isEmpty(grem)){
            mEtGrem.setText(grem);
        }
        if(!TextUtils.isEmpty(temperature)){
            mEtTemperature.setText(temperature);
        }
        if(!TextUtils.isEmpty(time)){
            mEtTime.setText(time);
        }
        if(!TextUtils.isEmpty(gremtitle)){
            mTvGrem.setText(gremtitle);
        }
        if(!TextUtils.isEmpty(temperaturetitle)){
            mTvTemperature.setText(temperaturetitle);
        }
        if(!TextUtils.isEmpty(timetitle)){
            mTvTime.setText(timetitle);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.positi_bn:
                if(positiveListener!= null){
                positiveListener.onpisitive(this);
            }
                dismiss();
                break;
            case R.id.navige_bn:
                if(negetiveListener!= null){
                   negetiveListener.onCancel(this);
                }
                dismiss();
                break;
        }
    }

    public EditText getmEtTemperaturecontent() {
        return mEtTemperature.findViewById(R.id.eta_temperature);
    }
    public interface onPositiveListener{
        void onpisitive(GremSetDialog dialog);
    }
    public interface onNegetiveListener{
        void onCancel(GremSetDialog dialog);
    }

}
